/**
 * @MethodobserverProxy.as
 * 
 * @author sodaChen mail:asframe@163.com
 * @version 1.0
 * <br>Copyright (C), 2012 ASFrame.com
 * <br>This program is protected by copyright laws.
 * <br>Program Name:ASFrame AStruts2
 * <br>Date:2012-5-5
 */
package com.asframe.astruts2.proxy
{
	import com.asframe.lang.IDisposable;
	import com.asframe.pattern.observer.IObserver;
	import com.asframe.slf4j.ILogger;
	import com.asframe.slf4j.LoggerFactory;
	
	/**
	 * Mediator代理方法观察者
	 * @author sodaChen
	 * @Date:2012-5-5
	 */
	public class MethodobserverProxy implements IObserver,IDisposable
	{
		/** 日志 **/
		private static var log		:ILogger = LoggerFactory.getLogger(MethodobserverProxy);
		/** 作为观察者的方法 **/
		private var method				:Function;
		private var target				:Object;
		
		public function MethodobserverProxy(target:Object,method:Function)
		{
			this.target = target;
			this.method = method;
		}
		
		public function replyNotice(notice:*, args:*=null):void
		{
			try
			{
				if(args is Array)
				{
					method.apply(target,args);
				}
				else
				{
					method.apply(target,[args]);
				}
			} 
			catch(error:Error) 
			{
				log.error("Mediator代理方法观察者相应通知发生错误，notice:" + notice + " args:",args,error);
			}
		}
		/**
		* 释放对象相关资源 
		* @param o:释放时需要的参数（不是必须的）
		* 
		*/		
		public function dispose(o:* = null):void
		{
			method = null;
			target = null;
		}
	}
}
